﻿<Page
    x:Name="pageRoot"
    x:Class="ReferenceTemplate.Windows8.DetailPage"
    DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ReferenceTemplate.Windows8"
    xmlns:common="using:ReferenceTemplate.Windows8.Common"
    xmlns:converter="using:ReferenceTemplate.Windows8.Converter"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">My Application</x:String>
        <converter:LoadURL x:Key="LoadURL"/>
        <DataTemplate x:Key="LinkDetailTemplate">
        	<Grid>
        		<ProgressRing HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,140,0,0" IsActive="True" Foreground="White" Width="100" Height="100"/>
                <WebView Margin="0,140,0,0" Source="{Binding URL, Converter={StaticResource LoadURL}, ConverterParameter={Binding Source={StaticResource Locator}, Path=Main}}" />
                <Grid Margin="115,0,0,0" Height="140" VerticalAlignment="Top">
                    <TextBlock HorizontalAlignment="Left" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Text="{Binding Title}" VerticalAlignment="Center" Style="{StaticResource HeaderTextBlockStyle}"/>
        		</Grid>
        	</Grid>
        </DataTemplate>
    </Page.Resources>
	<Page.BottomAppBar>
		<CommandBar>
            <AppBarButton Label="Abrir Link" Icon="OpenPane" Command="{Binding OpenLink}"/>
            <AppBarButton Label="Copiar Link" Icon="Copy" Command="{Binding CopyLink}"/>
            <AppBarButton Label="Anclar al inicio" Icon="Pin" Command="{Binding PinToStart}" IsEnabled="{Binding CanPinToStart}" />
		</CommandBar>
	</Page.BottomAppBar>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{Binding Color}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->

        <!--<FlipView x:Name="Links" ItemsSource="{Binding Links}" ItemTemplate="{StaticResource LinkDetailTemplate}" SelectedItem="{Binding SelectedLink, Mode=TwoWay}" Grid.RowSpan="2"/>-->
        <!--<WebView Margin="0" Source="{Binding SelectedLink.URL}" Grid.Row="1" />-->
        <Grid Grid.RowSpan="2" DataContext="{Binding SelectedLink}">
            <ProgressRing HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,140,0,0" IsActive="True" Foreground="White" Width="100" Height="100"/>
            <WebView Margin="0,140,0,0" Source="{Binding URL, Converter={StaticResource LoadURL}, ConverterParameter={Binding Source={StaticResource Locator}, Path=Main}}" />
            <Grid Margin="115,0,0,0" Height="140" VerticalAlignment="Top">
                <TextBlock HorizontalAlignment="Left" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Text="{Binding Title}" VerticalAlignment="Center" Style="{StaticResource HeaderTextBlockStyle}"/>
            </Grid>
        </Grid>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
        </Grid>
    </Grid>
</Page>
